import { Config } from '../types/config';

const STORAGE_KEY = 'abellaConfig';

// 默认配置
export const DEFAULT_CONFIG: Config = {
  // 公司信息
  companyName: 'ABELLA',
  companyIntro: 'Making tails wag and purrs rumble since 2015. Quality products for your beloved pets.',
  
  // 联系方式
  address: '123 Paws Avenue, Pet District, New York, NY 10012, USA',
  phone: '+1 (555) 123-WOOF',
  email: 'hello@abella-pets.com',
  whatsapp: '+1 (555) 987-PAWS',
  
  // 介绍视频
  introVideoUrl: 'https://images.unsplash.com/photo-1548199973-03cce0bbc87b?auto=format&fit=crop&w=1200&q=80',
  
  // 商品介绍PDF
  productCatalogs: {
    en: '#',
    cn: '#',
    es: '#'
  },
  
  // 社交平台网址
  socialLinks: {
    facebook: 'https://facebook.com',
    instagram: 'https://instagram.com',
    x: 'https://x.com',
    youtube: 'https://youtube.com',
    linkedin: 'https://linkedin.com'
  }
};

// 获取配置
export const getConfig = (): Config => {
  const savedConfig = localStorage.getItem(STORAGE_KEY);
  if (savedConfig) {
    return JSON.parse(savedConfig);
  }
  // 首次加载时，将默认配置保存到本地存储
  localStorage.setItem(STORAGE_KEY, JSON.stringify(DEFAULT_CONFIG));
  return DEFAULT_CONFIG;
};

// 保存配置
export const saveConfig = (config: Config): void => {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(config));
};

// 更新配置
export const updateConfig = (updates: Partial<Config>): Config => {
  const currentConfig = getConfig();
  const updatedConfig = { ...currentConfig, ...updates };
  saveConfig(updatedConfig);
  return updatedConfig;
};
